package coder.nav.controller;

import coder.nav.common.JwtToken;
import coder.nav.common.R;
import coder.nav.model.bo.NavTaskBO;
import coder.nav.model.bo.NavTaskQueryBO;
import coder.nav.model.vo.NavKeyValueVO;
import coder.nav.model.vo.NavTaskActionVO;
import coder.nav.model.vo.NavPageVO;
import coder.nav.model.vo.NavTaskVO;
import coder.nav.service.NavTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "定时任务")
@RestController
@RequestMapping("/task")
public class NavTaskController {

    @Autowired
    private NavTaskService taskService;

    @JwtToken
    @ApiOperation("定时任务-保存")
    @PostMapping("/save")
    public R<Void> save(@Validated @RequestBody NavTaskBO bo) {
        taskService.saveTask(bo);
        return new R<>();
    }

    @JwtToken
    @ApiOperation("定时任务-测试")
    @PostMapping("/debug")
    public R<Void> debug(@Validated @RequestBody NavTaskBO bo) {
        taskService.debugTask(bo);
        return new R<>();
    }

    @JwtToken
    @ApiOperation("定时任务-删除")
    @DeleteMapping("/delete")
    public R<Void> delete(@RequestParam("id") Long id) {
        taskService.deleteTask(id);
        return new R<>();
    }

    @JwtToken
    @ApiOperation("定时任务-分页")
    @PostMapping("/getPage")
    public R<NavPageVO<NavTaskVO>> getPage(@Validated @RequestBody NavTaskQueryBO bo) {
        return new R<>(taskService.getTaskPage(bo));
    }

    @JwtToken
    @ApiOperation("定时任务-详情")
    @GetMapping("/getInfo")
    public R<NavTaskVO> getInfo(@RequestParam("id") Long id) {
        return new R<>(taskService.getTaskInfo(id));
    }

    @JwtToken
    @ApiOperation("执行方法-下拉列表")
    @GetMapping("/getFunctionList")
    public R<List<NavKeyValueVO<String, String>>> getFunctionList() {
        return new R<>(taskService.getTaskFunctionList());
    }

}
